package cn.findviewbydream.evil.main.controller;

import cn.findviewbydream.evil.main.dao.TestDao;
import cn.findviewbydream.evil.main.dto.TestBean;
import cn.findviewbydream.evil.main.entity.UserEntity;
import cn.findviewbydream.evil.main.utils.WebUtil;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.gson.Gson;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/********************************************
 * 工程名：HebeuCS
 * 包名：cn.findviewbydream.evil.main.controller
 * 时间：16-10-31 下午3:21
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：
 ********************************************/
@Controller
public class TestController
{
    @RequestMapping("/test")
    public String test()
    {
        return "test";
    }

    @Autowired
    private TestDao testDao;

    @RequestMapping("/t")
    public String t(Model model)
    {
        model.addAttribute("test", testDao.selectContent(1));
        return "t";
    }


    @RequestMapping(value = "/test/get", produces = {"application/json;charset=utf-8"})
    @ResponseBody
    public ArrayList<TestBean> get(@RequestHeader HttpHeaders headers,
                                   HttpSession session)
    {
        System.out.println(session.getId());

        System.out.println(headers.get("from"));

        ArrayList<TestBean> list = new ArrayList<>();
        for (int i = 0; i < 10; i++)
        {
            TestBean testBean = new TestBean("name" + i, i + 20);
            list.add(testBean);
        }
        return list;
    }
}
